import Vue from 'vue'
import App from './App'
import store from './store'
import router from './router'
import VueResource from 'vue-resource'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-default/index.css'
import 'font-awesome/css/font-awesome.css'
import jQuery from 'jquery'

Vue.use(ElementUI)
Vue.use(VueResource)
store.state.User.token = localStorage.token 
let throttle = function(delay, action){
  let last = 0
  return function() {
    let curr = +new Date()
    if(curr - last > delay) {
      action.apply(this, arguments)
      last = curr
    }
  }
}

let cb = throttle(5000, function (response) {
    if(response.body.statusCode=='401'){
      this.$confirm('登录超时 请重新登录', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$router.push('/login')
      })
    }else if(response.status=='207'){
      this.$message.error("操作太频繁了")
    }
})

Vue.http.interceptors.push(function (request, next) {
  next(cb)
})

new Vue({
  el: '#app',
  render: h => h(App),
  store,
  router
})

